<template>
  <div class="rightArea">
    <div class="mengceng" v-if="mengcengShow" @click="resetListBtn"></div>
    <h1>回标</h1>
    <search-form ref="searchForms" @searchFormFn="searchFormFn"></search-form>
    <div class="groupBtn">
      <el-button
        v-if="hasQx('aph2_tender_ZBHB-QX-C19') || true"
        size="mini"
        type="primary"
        @click="searchListBtn"
        >查询</el-button
      >
      <el-button
        v-if="hasQx('aph2_tender_ZBHB-QX-C19') || true"
        size="mini"
        type="primary"
        @click="resetListBtn"
        >重置</el-button
      >
      <el-button
        v-if="hasQx('aph2_tender_ZBHB-QX-C11') || true"
        size="mini"
        type="primary"
        @click="returnBidFn"
        >回标</el-button
      >
    </div>
    <el-table
      :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
      :data="returnBidList"
      border
      size="mini"
      tooltip-effect="dark"
      style="width: 98%; margin: 0 auto"
      @selection-change="tableSearchFn"
    >
      <el-table-column
        align="center"
        type="selection"
        width="50"
      ></el-table-column>
      <el-table-column
        label="序号"
        width="50"
        type="index"
        align="center"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="commCode"
        label="业务单元"
      ></el-table-column>
      <el-table-column
        prop="tenderName"
        label="招标项目名称"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        prop="tenderNumber"
        label="招标编号"
        show-overflow-tooltip
      ></el-table-column>
      <!-- <el-table-column prop="contractDemand" label="招标范围" width="100">
        <template slot-scope="scope">
          <p v-if="scope.row.contractDemand.length<6">{{scope.row.contractDemand}}</p>
          <el-popover
           v-if="scope.row.contractDemand.length>5"
            placement="top"
            popper-class="fw"
            trigger="hover"
            :content="scope.row.contractDemand">
            <p style="width:100%;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;"
              slot="reference"
            >{{scope.row.contractDemand}}</p>
          </el-popover>
        </template>
      </el-table-column> -->
      <el-table-column label="招标状态">
        <template slot-scope="scope">
          <div v-if="scope.row.tenderFileStatus == 'lost'">
            <span v-if="scope.row.tenderScheduleStatus == 'tenderFileAnswer'"
              >招标答疑文件完成答疑(流标)</span
            >
            <span v-if="scope.row.tenderScheduleStatus == 'tenderLost'"
              >流标</span
            >
            <span v-if="scope.row.tenderScheduleStatus == 'tenderOverReturn'"
              >完成回标(流标)</span
            >
            <span v-if="scope.row.tenderScheduleStatus == 'tenderFileRelease'"
              >招标文件已发布(流标)</span
            >
          </div>
          <div v-if="scope.row.tenderFileStatus != 'lost'">
            <span v-if="scope.row.tenderScheduleStatus == 'tenderFileAnswer'"
              >招标答疑文件完成答疑</span
            >
            <span v-if="scope.row.tenderScheduleStatus == 'tenderLost'"
              >流标</span
            >
            <span v-if="scope.row.tenderScheduleStatus == 'tenderOverReturn'"
              >完成回标</span
            >
            <span v-if="scope.row.tenderScheduleStatus == 'tenderFileRelease'"
              >招标文件已发布</span
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination-z
      :total="total"
      :fromWhere="fromWhere"
      @fatherMethod="fatherMethod"
    ></pagination-z>
  </div>
</template>

<script>
export default {
  data() {
    return {
      returnBidData: {
        tenderNumber: "", // 招标编号
        tenderName: "", // 招标名称
        tenderType: "", // 招标方式
        commCode: "", // 业务单元
        page: 1,
        size: 10,
      },
      returnBidList: [],
      fromWhere: "documentApprovalHome",
      sso_sessionid: this.$store.state.sso_sessionid,
      total: 0,
      selectList: [],
      mengcengShow: false,
    };
  },
  mounted() {
    this.getTenderReturnList(this.returnBidData);
  },
  methods: {
    hasQx(value) {
      return this.commonFn.hasQx(value, this);
    },
    // 搜索表单回调
    searchFormFn(obj) {
      console.log("this.returnBidData", this.returnBidData);
      console.log("obj", obj);
      Object.assign(this.returnBidData, obj);
      this.search(this.returnBidData);
    },
    search(data) {
      var newDataList = new Array();

      if (data.tenderName != null) {
        //console.log(data.tenderName)
        for (var i = 0; i < this.returnBidList.length; i++) {
          // console.log("第",i,"个", this.returnBidList[i].tenderName.indexOf(data.tenderName + ''))
          if (
            this.returnBidList[i].tenderName.indexOf(data.tenderName + "") != -1
          ) {
            // array.splice( start, deleteCount );
            //this.returnBidList.splice(i, 1);
            newDataList.push(this.returnBidList[i]);
          }
        }
        this.returnBidList = newDataList;
      }
      //  console.log('新的数组长度:', this.returnBidList.length)
      newDataList = [];
      if (data.tenderNumber != null && data.tenderNumber != "") {
        // console.log(data.tenderNumber)
        for (var i = 0; i < this.returnBidList.length; i++) {
          let numberStr = this.returnBidList[i].tenderNumber + "";
          //   console.log("第",i,"个", numberStr.indexOf(data.tenderNumber + ''))

          if (numberStr.indexOf(data.tenderNumber + "") != -1) {
            // array.splice(start, deleteCount);
            // this.returnBidList.splice(i, 1);
            newDataList.push(this.returnBidList[i]);
          }
        }
        this.returnBidList = newDataList;
      }
    },
    //  表格勾选事件
    tableSearchFn(v) {
      this.selectList = v;
    },
    // 分页回调函数
    fatherMethod(page, size) {
      this.returnBidData.page = page;
      this.returnBidData.size = size;
      this.getTenderReturnList(this.returnBidData);
    },
    // 查询按钮
    searchListBtn() {
      this.returnBidData.page = 1;
      this.getTenderReturnList(this.returnBidData);
    },
    //  重置
    resetListBtn() {
      this.returnBidData = {
        tenderNumber: "", // 招标编号
        tenderName: "", // 招标名称
        tenderType: "", // 招标方式
        commCode: "", // 业务单元
        page: 1,
        size: 10,
      };
      this.$refs.searchForms.resetFn();
      this.mengcengShow = false;
      this.getTenderReturnList(this.returnBidData);
    },
    // 查询
    getTenderReturnList(params) {
      this.$api.modular
        .getTenderReturn(this.sso_sessionid, params)
        .then((res) => {
          console.log(res);

          if (res.status == 200) {
            this.returnBidList = res.data.data.list;
            this.total = Number(res.data.count);
          } else {
            this.$message.error(res.message);
          }
        })
        .catch(() => {});
    },

    // 回标
    returnBidFn() {
      if (this.selectList.length != 1) {
        this.$message.error("请选择单个项目");
        return false;
      }
      var params = {
        openTenderType: 0,
        tenderFileCode: this.selectList[0].tenderNumber,
      };
      this.$api.modular
        .getScheduleMax(this.sso_sessionid, params)
        .then((res) => {
          if (res.status == 200) {
            this.$message({
          message: '设置回标成功！！！',
          type: 'success'
        });
            
            this.getTenderReturnList(this.returnBidData);
          } else {
            this.$message.error(res.message);
            return false;
          }
        });
      // this.commonFn.routerProcess(this.selectList, 5, this);
    },
  },
};
</script>

<style scoped>
.fileSearch {
  text-align: left;
  margin-bottom: 20px;
}
.fileSearch .el-form-item {
  width: 32%;
  margin-bottom: 0;
  margin-top: 15px;
  margin-left: 20px;
}
.groupBtn {
  text-align: right;
  padding-right: 1%;
  margin-bottom: 20px;
}
</style>
